﻿<%@ Control Language="C#" AutoEventWireup="true" Inherits="HL.Lib.MVC.CPViewControl" %>
<%
    var model = ViewBag.Model as ModNewsPropertyModel;
    var entity = ViewBag.Data as ModNewsPropertyEntity;
    var List = ViewBag.ListProperty as List<ModPropertyEntity>;
%>
<form id="hlForm" name="hlForm" method="post">
<input type="hidden" id="_hl_action" name="_hl_action" />
<div id="toolbar-box">
    <div class="t">
        <div class="t">
            <div class="t">
            </div>
        </div>
    </div>
    <div class="m">
        <div class="toolbar-list" id="toolbar">
            <%=GetDefaultAddCommand() %>
        </div>
        <div class="pagetitle icon-48-generic">
            <h2>
                Thuộc tính :
                <%=  model.RecordID > 0 ? "Chỉnh sửa" : "Thêm mới"%></h2>
        </div>
        <div class="clr">
        </div>
    </div>
    <div class="b">
        <div class="b">
            <div class="b">
            </div>
        </div>
    </div>
</div>
<div class="clr">
</div>
<%= ShowMessage()%>
<div id="element-box">
    <div class="t">
        <div class="t">
            <div class="t">
            </div>
        </div>
    </div>
    <div class="m">
        <div class="col width-100">
            <table class="admintable">
                <tr>
                    <td class="key">
                        <label>
                            Nhóm thuộc tính :</label>
                    </td>
                    <td>
                    <%if (model.RecordID > 0)
                      { %>
                      <input type="hidden" name="PropertyID" value="<%=entity.PropertyID %>" />
                      <label style=" margin-left:30px; font-weight:bold; font-size:1.091em;"><%=entity.getProperty().Name %></label>
                      <%}
                      else
                      { %>
                        <select name="PropertyID" id="PropertyID" class="text_input" onchange="LoadPropertyValue(this.value);">
                            <option value="0">-</option>
                            <%for (int i = 0; List != null && i < List.Count; i++)
                              { %>
                            <option <%if(entity.PropertyID==List[i].ID) {%> selected <%} %> value="<%= List[i].ID%>">
                                <%= List[i].Name%></option>
                            <%} %>
                        </select>
                        <%} %>
                    </td>
                </tr>
                <tr>
                    <td class="key">
                        <label>
                            Giá trị thuộc tính :</label>
                    </td>
                    <td>
                    <div id="PropertyValue">
                    
                    </div>
                    </td>
                </tr>
            </table>
        </div>
        <div class="clr">
        </div>
    </div>
    <div class="b">
        <div class="b">
            <div class="b">
            </div>
        </div>
    </div>
</div>
</form>
<script type="text/javascript">
    function LoadPropertyValue(PropertyID) {
        var ranNum = Math.floor(Math.random() * 999999);
        sLink = '/{CPPath}/Ajax/LoadPropertyValue.aspx/PropertyID/' + PropertyID + '/NewsID/<%=model.NewsID %>?rnd=' + ranNum;
        AjaxRequest.get(
	        {
	            'url': sLink
	        , 'onSuccess': function (req) {
	            with (req.responseXML.getElementsByTagName('Item').item(0)) {
	                var content = getNodeValue(getElementsByTagName('Html'));
	                document.getElementById("PropertyValue").innerHTML = '<select class="text_input" name="PropertyValueID"><option value="0">-Chọn giá trị thuộc tính-</option>' + content + '</select>';
	            }
	        }
	        , 'onError': function (req) { }
	        }
        )
	}
    <%if(model.RecordID>0){ %>LoadPropertyValue('<%=entity.PropertyID %>');<%} %>
</script>